<?php

use yii\helpers\Html;
use kartik\grid\GridView;

/* @var $this yii\web\View */
/* @var $searchModel common\models\product\ProductSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '货品';
$this->params['breadcrumbs'][] = $this->title;

$saleType = [''=>'不过滤',0=>'下架',1=>'上架'];
?>

<style>
    
</style>

<div class="product-index">
    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>


    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],

            //'id',
            [
                'attribute' => 'goods_name',
                'header'=>'商品名称',
                'content' => function($data, $row) {
                    $html=$data->goods->name;
                    !empty($data->goods_attr_str) && $html.="<div class=\"goods-attr\">{$data->goods_attr_str}</div>";
                    return $html;
                },
            ],
            'sn',
            'sn_intel',
            'sn_purchase',
            [
                'attribute' => 'is_on_sale',
                'header'=>'销售状态',
                'filterType'=>GridView::FILTER_SELECT2,
                'filter'=>$saleType, 
                'content' => function($data, $row) {
                    return $data->goods->is_on_sale==1?'<div class="green">上架</div>':'<div class="red">下架</div>';
                },
            ],
            // 'goods_attr',
            // 'goods_attr_str',
             'number_stock',
             'number_lock',
            // 'price_market',
            // 'price_cost',
            // 'img',
            // 'name_short',
            // 'is_buy_min_disable',
            // 'is_buy_setp_disable',
            // 'weight',
            // 'supplier_id',
             'slot',

            [
                'class' => 'yii\grid\ActionColumn',
                'buttons'=>[
                    'view' ,
                    'update' => function ($url, $model, $key) {
                        return Html::a('<span class="glyphicon glyphicon-pencil"></span>', ['/supplier/goods/default/update','id'=>$model->goods_id],['target'=>'_blank']);
                    },
                    'delete' => function ($url, $model, $key) {
                        return '';
                    },
                ],
            ],
        ],
    ]); ?>

</div>
